package com.javafamily.familydemo.controller;

import com.alibaba.druid.stat.DruidStatManagerFacade;
import com.javafamily.familydemo.model.Customer;
import com.javafamily.familydemo.model.Pets;
import com.javafamily.familydemo.model.Response;
import com.javafamily.familydemo.service.PetsService;
import io.swagger.annotations.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@Slf4j
@RestController
public class PetsController {

    @Resource
    PetsService petsService;

    // 根据id，查询一只宠物信息
    @RequestMapping(value = "/pets/{id}", method = RequestMethod.GET)
    public Response getPets(@PathVariable("id") long id) {
        Pets pets = petsService.getPets(id);
        log.info("pets" + pets);
        return Response.success(pets);
    }

    @RequestMapping(value = "/pets", method = RequestMethod.POST)
    public Response savePets(@RequestBody Pets pets) {
        petsService.savePets(pets);
        log.info("savePets" + pets);
        return Response.success();
    }

    // 修改一只宠物信息
    @RequestMapping(value = "/pets", method = RequestMethod.PUT)
    public Response updatePets(@RequestBody Pets pets) {
        petsService.updatePets(pets);
        log.info("updatePets" + pets);

        return Response.success(pets);

    }

    // 根据id，删除一只宠物信息
    @RequestMapping(value = "/pets/{id}", method = RequestMethod.DELETE)
    public Response deletePets(@PathVariable("id") Long id) {
        petsService.deletePets(id);
        log.info("deletePets" + id);
        return Response.success();
    }

    // 查询所有宠物信息
    @RequestMapping(value = "/pets", method = RequestMethod.GET)
    public Response getPets() {
        List<Pets> pets = petsService.getAll();
        log.info("pets" + pets);
        return Response.success(pets);
    }

    @GetMapping("/data")
    public Object druid(){
        return DruidStatManagerFacade.getInstance().getDataSourceStatDataList();
    }

}
